import { typePageSelect } from '@/api/goodsInfo'
import { ref } from 'vue'
import _ from 'lodash'
export default () => {
  const goodTypeTotal = ref(0)
  const getGoodTypesLoading = ref(false)
  const goodTypes = ref<Array<GoodTypes>>([])
  const getGoodTypesParam = ref({
    limit: 50,
    page: 1,
    name: '',
  })
  const getGoodTypes = _.debounce(
    async () => {
      getGoodTypesLoading.value = true
      const res = await typePageSelect(getGoodTypesParam.value)
      goodTypes.value = res.data.data.rows
      goodTypeTotal.value = Number(res.data.data.total)
      getGoodTypesLoading.value = false
    },
    1000,
    { leading: false },
  )

  return {
    goodTypes,
    goodTypeTotal,
    getGoodTypesParam,
    getGoodTypesLoading,
    getGoodTypes,
  }
}
